﻿package mortal.game.view.common
{
    import com.mui.controls.*;
    import com.mui.core.*;

    public class CellsGridSprite extends GSprite
    {
        public var colNum:uint = 1;
        public var vCellWid:uint = 100;
        public var hCellWid:uint = 100;
        public var cellArr:Array;
        public var genCellFun:Function;

        public function CellsGridSprite()
        {
            this.genCellFun = UIFactory.getUICompoment;
            return;
        }// end function

        public function genCells(param1:uint, ... args) : void
        {
            var _loc_4:* = undefined;
            if (this.genCellFun == null)
            {
                return;
            }
            this.disposeCells();
            this.cellArr = [];
            args = 0;
            while (args < param1)
            {
                
                _loc_4 = constructCell(this.genCellFun, args);
                _loc_4.x = args % this.colNum * this.vCellWid;
                _loc_4.y = int(args / this.colNum) * this.hCellWid;
                this.addChild(_loc_4);
                this.cellArr.push(_loc_4);
                args++;
            }
            return;
        }// end function

        private function genOneCell() : void
        {
            this.genCellFun();
            return;
        }// end function

        public function disposeCells(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            var _loc_3:* = undefined;
            var _loc_4:IFrUI = null;
            if (this.cellArr)
            {
                _loc_2 = 0;
                while (_loc_2 < this.cellArr.length)
                {
                    
                    _loc_3 = this.cellArr[_loc_2];
                    _loc_4 = _loc_3 as IFrUI;
                    if (_loc_4)
                    {
                        _loc_4.dispose(param1);
                    }
                    _loc_2++;
                }
                this.cellArr = null;
            }
            return;
        }// end function

        public function updateAll(param1:Array, param2:Class, param3:String, param4:Boolean = true) : void
        {
            var _loc_6:* = undefined;
            var _loc_7:* = undefined;
            if (param1 == null)
            {
                return;
            }
            if (param2 == null)
            {
                this.genCells(param1.length);
            }
            else
            {
                this.genCells(param1.length, param2);
            }
            var _loc_5:int = 0;
            while (_loc_5 < param1.length)
            {
                
                _loc_6 = this.cellArr[_loc_5];
                _loc_7 = param1[_loc_5];
                if (_loc_6)
                {
                    if (param4)
                    {
                        var _loc_8:* = _loc_6;
                        _loc_8._loc_6[param3](_loc_7);
                    }
                    else
                    {
                        _loc_6[param3] = _loc_7;
                    }
                }
                _loc_5++;
            }
            return;
        }// end function

        public function updateAllNotDispose(param1:Array, param2:Class, param3:String, param4:Boolean = true) : void
        {
            var _loc_6:* = undefined;
            var _loc_7:* = undefined;
            if (param1 == null || this.cellArr == null)
            {
                return;
            }
            var _loc_5:int = 0;
            while (_loc_5 < param1.length)
            {
                
                _loc_6 = this.cellArr[_loc_5];
                _loc_7 = param1[_loc_5];
                if (_loc_6)
                {
                    if (param4)
                    {
                        var _loc_8:* = _loc_6;
                        _loc_8._loc_6[param3](_loc_7);
                    }
                    else
                    {
                        _loc_6[param3] = _loc_7;
                    }
                }
                _loc_5++;
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            super.dispose(param1);
            this.disposeCells(param1);
            this.genCellFun = null;
            return;
        }// end function

        private static function constructCell(param1:Function, param2:Array)
        {
            switch(param2.length)
            {
                case 0:
                {
                    return CellsGridSprite.param1();
                }
                case 1:
                {
                    return CellsGridSprite.param1(param2[0]);
                }
                case 2:
                {
                    return CellsGridSprite.param1(param2[0], param2[1]);
                }
                case 3:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2]);
                }
                case 4:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3]);
                }
                case 5:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4]);
                }
                case 6:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4], param2[5]);
                }
                case 7:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4], param2[5], param2[6]);
                }
                case 8:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4], param2[5], param2[6], param2[7]);
                }
                case 9:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4], param2[5], param2[6], param2[7], param2[8]);
                }
                case 10:
                {
                    return CellsGridSprite.param1(param2[0], param2[1], param2[2], param2[3], param2[4], param2[5], param2[6], param2[7], param2[8], param2[9]);
                }
                default:
                {
                    return null;
                    break;
                }
            }
        }// end function

    }
}
